package com.itheima.chapter08.set.map.treemap;

import java.util.Set;
import java.util.TreeMap;
//统计每个字符出现的次数 输出形式为a(2)b(3)...

public class TreeMapdemo2 {
    public static void main(String[] args) {
        String s ="aababcabcdabcde";
        TreeMap<Character,Integer> tm =new TreeMap<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (!tm.containsKey(c)){
                tm.put(c,1);
            }else {
                Integer count =tm.get(c);
                count++;
                tm.put(c,count);
            }
        }
        Set<Character> keySet = tm.keySet();
        for (Character key : keySet) {
            Integer i = tm.get(key);
            System.out.println(key +"("+i+")");
        }
    }
}
